<template>
  <view class="normal-login-container">
    <search placeholder="请输入车牌号" @input="inputChange">
      <view class="flex right20 align-center" slot="right">
        <!--右侧缩略搜索-->
        <uni-icons type="tune" :color="isAllEmpty(queryParams)?'#333':'#1890FF'" @click="handleOpen" size="25"/>
      </view>
    </search>

    <mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
      <view class="item-wrap" v-for="(item,index) in list" :key="index" @click="goDetail(item)">

        <view class="title-wrap lineBottom10">
          <text>{{ item.vinNo || '' }}</text>
          <text>{{ item.carNo || '' }}</text>
        </view>

        <view class="flex-row align-stretch">
          <view class="flex-col flex1">

            <view class="text-line">
              <text class="text-name">常规处置编号:</text>
              <text class="text-value">{{ item.vehicleDisposalNo|filterNull }}</text>
            </view>

            <view class="text-line">
              <text class="text-name">品牌车系车型:</text>
              <text class="text-value">
                {{ item.brandName|filterNull }}/{{ item.seriesName|filterNull }}/{{ item.modelName|filterNull }}
              </text>
            </view>

            <view class="text-line">
              <text class="text-name">车辆产权:</text>
              <text class="text-value">{{ item.propertyRightName|filterNull }}</text>
            </view>

            <view class="text-line">
              <text class="text-name">处理状态:</text>
              <text class="text-value">{{ handleLabel(disposalList, item.disposalStatus) }}</text>
            </view>

          </view>

        </view>

        <view class="btn-wrap lineTop20">

          <button size="mini" v-if="[2,5].includes(Number(item.disposalStatus))"
                  @click.stop="handleSubmitResult(item)"
                  type="primary">提交处置结果
          </button>

          <button size="mini" v-if="[2].includes(Number(item.disposalStatus))"
                  @click.stop="handleSalvageValue(item)"
                  type="primary">修改残值
          </button>

          <button size="mini" v-if="[6].includes(Number(item.disposalStatus))"
                  @click.stop="handleUploadContract(item)"
                  type="primary">上传合同
          </button>

          <button size="mini" v-if="[6,7,8,9].includes(Number(item.disposalStatus))"
                  @click.stop="handleUnderwriterDefault(item)"
                  type="primary">承销商违约
          </button>

          <button size="mini" v-if="[7].includes(Number(item.disposalStatus))"
                  @click.stop="handleSubmitPaymentProof(item)"
                  type="primary">提交付款凭证
          </button>

          <button size="mini" v-if="[10].includes(Number(item.disposalStatus))"
                  @click.stop="handleSubmitProcedure(item)"
                  type="primary">提交手续
          </button>
        </view>

      </view>
    </mescroll-body>

    <condition-search ref="refConditionSearch"
                      v-model="queryParams" @reset="reset" @confirm="confirm"/>
    <!--上传合同-->
    <upload-contract ref="refUploadContract" @success="successList"/>

    <!--承销商违约-->
    <underwriter ref="refUnderwriterDefault" @success="successList"/>

    <!--提交付款凭证-->
    <payment ref="refPaymentDocument" @success="successList"/>

    <!-- 提交手续-->
    <procedure ref="refSubmitProcedure" @success="successList"/>
  </view>
</template>

<script>

import * as apis from '@/api/routineHandle'
import ConditionSearch from "./components/conditionSearch.vue";
import uploadContract from "./components/uploadContract.vue"
import underwriter from "./components/underwriter.vue"
import payment from "./components/payment.vue"
import procedure from "./components/procedure.vue"

export default {
  name: 'list',
  dicts: ['disposal_status_type'],
  components: {
    ConditionSearch,
    uploadContract,
    underwriter,
    payment,
    procedure
  },
  computed: {
    handleLabel() {
      return function (arr, type) {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },

    disposalList() {
      return this.dict.type.disposal_status_type
    }
  },
  watch: {},
  data() {
    return {
      carNo: '',
      list: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNo: '',
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
        warningState: "",
        applicationStartTime: '',
        applicationEndTime: ''
      },
    };
  },
  created() {
  },
  mounted() {
  },
  onLoad() {
    uni.$on('refBackList', call=>{
      this.mescroll.triggerDownScroll();
    })
  },
  methods: {
    inputChange(val) {
      this.queryParams.carNo = val;
      this.mescroll.resetUpScroll();
    },

    isAllEmpty() {

    },

    //打开搜索弹框
    handleOpen() {
      this.$refs.refConditionSearch.open();
    },

    confirm(val) {
      this.queryParams = val;
      this.mescroll.resetUpScroll();
    },

    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
      }
      this.mescroll.resetUpScroll();
    },

    async upCallback(page) {
      var params = {
        pageNum: page.num,
        pageSize: page.size,
        ...this.queryParams,
      };
      try {
        const res = await apis?.handleList(params);
        //设置列表数据
        if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
        res.rows.forEach((item) => {
          item.check = false;
        });
        this.list = this.list.concat(res.rows); //追加新数据
        this.mescroll.endBySize(res.rows.length, res.total);
      } catch (e) {
        //联网失败, 结束加载
        this.mescroll.endErr();
      }
    },

    //详情
    goDetail(val) {
      let url = `/pages/VehiclePage/routineHandle/details?id=${val.vehicleDisposalId}&flowId=${val.flowId}&type=view`;
      this.$tab.navigateTo(url);
    },

    //提交处置结果
    handleSubmitResult(val) {
      let url = `/pages/VehiclePage/routineHandle/result?id=${val.vehicleDisposalId}&type=edit`;
      this.$tab.navigateTo(url);
    },

    //修改残值
    handleSalvageValue(val) {
      let url = `/pages/VehiclePage/routineHandle/editSalvage?id=${val.vehicleDisposalId}&type=edit`;
      this.$tab.navigateTo(url);
    },

    //上传合同
    handleUploadContract(row) {
      this.$refs.refUploadContract.open(row.vehicleDisposalId)
    },

    //承销商违约
    handleUnderwriterDefault(row) {
      this.$refs.refUnderwriterDefault.open(row)
    },

    //提交付款凭证
    handleSubmitPaymentProof(row) {
      this.$refs.refPaymentDocument.open(row)
    },

    //提交手续
    handleSubmitProcedure(row) {
      this.$refs.refSubmitProcedure.open(row)
    },

    successList() {
      this.mescroll.triggerDownScroll();
    },

  },
};
</script>

<style scoped lang=""></style>


